package com.wj.jiangan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wj.jiangan.mapper.ClientMapper;
import com.wj.jiangan.pojo.Client;
import com.wj.jiangan.pojo.vo.ClientVo;
import com.wj.jiangan.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wj
 * @since 2019-11-05
 */
@Service
public class ClientServiceImpl implements IClientService{
	@Autowired
	private ClientMapper clientMapper;

	@Override
	public List<Client> querAllClien(){
		return clientMapper.selectList(null);
	}

	@Override
	public IPage<ClientVo> findClientByPage(Page page, Map<String,Object> param){

		Integer pid = (Integer) param.get("pid");
		Integer eid = (Integer) param.get("eid");
		Integer cid = (Integer) param.get("cid");

		return clientMapper.queryByClientPage(page, pid, eid, cid);
	}

	@Override
	public IPage<Client> findClientByPage(Page<Client> page, Integer cis){
		QueryWrapper<Client> client = new QueryWrapper<>();
		client.eq("c_is", cis);
		return clientMapper.selectPage(page, client);
	}

	@Override
	public int addAllClien(Client client){
		return clientMapper.insert(client);
	}

	@Override
	public int updateAllClien(Client client){
		return clientMapper.updateById(client);

	}

	@Override
	public List<Client> findClientByEid(int eid){
		QueryWrapper<Client> qw = new QueryWrapper<>();
		qw.eq("e_id", eid);
		return clientMapper.selectList(qw);
	}

	@Override
	public Integer findClientIdByEmpIds(List<java.lang.Object> objects){
		QueryWrapper<Client> qw = new QueryWrapper<>();
		qw.eq("c_is", 1);
		qw.in("e_id", objects);
		Integer integer = clientMapper.selectCount(qw);
		return integer;
	}

	@Override
	public void updateClient(Client client, QueryWrapper queryWrapper){
		clientMapper.update(client, queryWrapper);
	}
}
